<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>商品列表 - 销售区域</title>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_head.php');?>
</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">
<!-- BEGIN HEADER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/head.php');?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" > 
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include($this->c['_homes']['_viewsHome'].'/_global/menu.php');?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR --> 
  <!-- BEGIN PAGE -->
  <div class="page-content"> 
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title"> 销售区域 </h3>
        <ul class="page-breadcrumb breadcrumb">
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 商品管理<i class="icon-angle-right"></i> </li>
          <li> <a href="/goods/goodslist">商品列表</a> <i class="icon-angle-right"></i> </li>
          <li>销售区域</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB--> 
      </div>
    </div>
    <!-- END PAGE HEADER--> 
    <!-- BEGIN PAGE CONTENT-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE FORM PORTLET-->
          <div class="tabbable tabbable-custom boxless">
            <div class="tab-content"> 
           		 <!--Tab0-->
              <div class="tab-pane active" id="tab_0">
                <div class="portlet box blue ">
                  <div class="portlet-title">
                    <div class="caption"> <i class="icon-reorder"></i> 选择商品区域</div>
                  </div>
                  <div class="portlet-body form">
                  <form class="form-horizontal" method="post" id="_frm" action="/goods/goods_region" role="form">
                    <div class="form-body">
                    <div  style="width:350px;height:30px;margin-bottom:10px;">
		                 <div id="region" style="width:200px;height:30px;border:solid 1px #4B8DF8;float:left;line-height:30px;text-indent:1em;">
		                      
		                   </div>
		                   <input type="button" onclick="reduction()" style="width:60px;height:30px;margin-left:40px;float:left;" class="btn blue"  value="还原"/>
                      </div>
                      <div class="form-group">
                        <div class="col-md-5">
                          <select id="_in_brand_1" multiple="multiple" class="form-control" size="20">
                      		 <?php
		                        if($this->province){
		                          foreach($this->province as $v){
		                              echo '<option value="'.$v['region_id'].'" ondblclick="choice_province(1)">'.$v['region_name'].'</option>';
		                            }
		                          }
		                        ?>
                          </select>
                        </div>
                      
                      <div class="col-md-1">
                      <p><input type="button" class="btn blue" value=" &gt;&gt; "  onclick="addrmb()"></p><br>
                      <p>
                      <input type="button" class="btn blue" value=" &lt;&lt; " onclick="delrmb()"></p>
                      </div>
                      <div class="col-md-5">
                          <select id="_in_brand_2" name="second[]" multiple="multiple" class="form-control" size="20">
                   					 <?php
		                        if($this->region){
		                          foreach($this->region as $v){
		                              echo '<option value="'.$v['region_id'].'">'.$v['region_name'].'</option>';
		                            }
		                          }
		                        ?>
                            </select>
                      </div>
                      </div>
                    </div>
                    <div class="form-actions fluid">
                      <div class="col-md-offset-3 col-md-9"> 
                      <input name="goods_id" type="hidden" value="<?php echo $this->goods_id;?>"/>             
                      <input type="button"  class="btn blue"  onclick="discount()" value="提交"/>
                      </div>
                    </div>
                  </div>
                </div>
                </form>
              </div>
            </div>
          </div>
        <!-- END SAMPLE FORM PORTLET--> 
      </div>
    </div>
    <!-- END PAGE CONTENT--> 
  </div>
  <!-- END PAGE --> 
</div>
<!-- END CONTAINER --> 
<!-- END CONTAINER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/_footer.php');?>
<script>
jQuery(document).ready(function() {    
  App.init(); 
});
</script> 
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
<script>
function choice_province(o){
	var _region="";
	var str=""
	var num=0;
	var region_id=$("#_in_brand_1").find("option:selected").val();
	var region_name=$("#_in_brand_1").find("option:selected").text();
	num=o+1;
		if(num==2){
			$("#region").html(region_name);			
		}else if(num==3){
			var con=$("#region").html();
			$("#region").html(con+'-'+region_name);				
		}else if(num>3){
			var con=$("#region").html();
			$("#region").html(con);			
			}	
	$.post("/goods/choice",{"region_id":region_id},function(res){
		if(res.code=='200'){
			for(i=0;i<res.data.length;i++){
				str+='<option value="'+res.data[i].region_id+'" ondblclick="choice_province('+num+')">'+res.data[i].region_name+'</option>'
				}
			
		}else{
			addrmb();
			}
			$("#_in_brand_1").html(str);
	},'json');
}
function addrmb(){
	var _add=true;
	var _id="";
	var _val="";
	$("#_in_brand_1").find("option:selected").each(function(){
		_id=$(this).val();
		_val=$(this).text();
		$("#_in_brand_2 option").each(function(){
				if(_id==$(this).val()){
					_add=false;
				}
			});
		if(_add==true){
			$("#_in_brand_2").append('<option value="'+_id+'" ondblclick="delrmb()">'+_val+'</option>');
			}
   	  });
  }
function delrmb(){
	$("#_in_brand_2").find("option:selected").remove();
}
function reduction(){
	var str="";
	$.post("/goods/choice",{"region_id":1},function(res){
		if(res.code=='200'){
			for(i=0;i<res.data.length;i++){
				str+='<option value="'+res.data[i].region_id+'" ondblclick="choice_province(1)">'+res.data[i].region_name+'</option>'
				}
			
		}
		$("#region").html('');	
		$("#_in_brand_1").html(str);
	},'json');
	
}
function discount(){
    $("#_in_brand_2 option").attr("selected","selected"); 
    $("#_frm").submit();
    }

</script>
</html>
